layui.use(['table', 'form', 'jquery'], function() {
    let  table = layui.table;
    let  form = layui.form;
    let  $ = layui.jquery;
    let  cols = [
        [
            {
                field: 'name',
                title: '姓名',
                unresize: true,
                align: 'center'
            },{
                field: 'sex',
                title: '性别',
                unresize: true,
                align: 'center'
            },{
                field: 'course_name',
                title: '咨询课程',
                unresize: true,
                align: 'center'
            },{
                field: 'phone',
                title: '手机号',
                unresize: true,
                align: 'center'
            },{
                field: 'return_time',
                title: '计划回访',
                unresize: true,
                align: 'center'
            },{
                field: 'return_number',
                title: '回访次数',
                unresize: true,
                align: 'center'
            },{
                field: 'campus_name',
                title: '校区',
                unresize: true,
                align: 'center'
            },{
                field: 'source_name',
                title: '来源',
                unresize: true,
                align: 'center'
            },{
                field: 'counselor_name',
                title: '顾问',
                unresize: true,
                align: 'center'
            },{
                field: 'status',
                title: '状态',
                unresize: true,
                align: 'center'
            }
        ]
    ]

    table.render({
        elem: '#dataTable',
        url: 'index',
        page: true,
        cols: cols,
        skin: 'line',
        toolbar: '#toolbar',
        done: function(res,curr,count) {
            var that = this.elem.next();
            if (res.data){
                res.data.forEach((item,index) => {
                    var colorId = localStorage.getItem("theme-color")
                    if (index % 2 == 0) {
                         tr = that.find('.layui-table-box tbody tr[data-index='+ index +']').css('background-color',colourDeal(colorId));
                    } else {
                         tr = that.find('.layui-table-box tbody tr[data-index='+ index +']').css('background-color');
                    }
                });
            }
        },
        defaultToolbar: [{
            layEvent: 'refresh',
            icon: 'layui-icon-refresh',
        }, 'filter']
    });

    form.on('submit(query)', function(data) {
        table.reload('dataTable', {
            url: 'advisory',
            where: data.field,
            page:{curr: 1}
        })
        return false;
    });


    table.on('toolbar(dataTable)', function(obj) {
        if (obj.event === 'refresh') {
            table.reload('dataTable');
        }
    });
    if (typeof width !== 'number' || width === 0) {
        width = $(window).width() * 0.8;
    }
    if (typeof height !== 'number' || height === 0) {
        height = $(window).height() - 20;
    }

})